﻿$(document).ready(function(){	
	
	//忘记密码
	$("#cellphone").blur(function(){
		if(!checkPhone($("#cellphone").val())){
			$("#cellphone").parent().next("td").find("span").html("<span class=red>请输入正确手机号</span>");
			return false;	
		}else{
			$("#cellphone").parent().next("td").find("span").html("√");
		}
	});
	$("#randomCode").blur(function(){
		if(isNaN($("#randomCode").val()) || $("#randomCode").val().length != 6){
			$("#randomCode").parent().next("td").find("span").html("<span class=red>请输入6位数字验证码</span>");
			return false;
		}else{
			$("#randomCode").parent().next("td").find("span").html("√");	
		}
	});
	
	$("#getCode").click(function(){		
		if($(this).hasClass("canot")){
			return false;
		}
		if(!checkPhone($("#cellphone").val())){
			$("#cellphone").parent().next("td").find("span").html("<span class=red>请输入正确手机号</span>");
			$("#cellphone").focus();
			return false;	
		}
		$.ajax({
			type: "POST",
			url: contextPath+"/media/user/open/sendCode4password.do",
			data: {"cellphone":$("#cellphone").val()},
			success: function (data) {
				if(data.status == 0){
					var i=30;
					$("#getCode").addClass("canot").val(i+"秒后获取");		
					var reSend=setInterval(function(){
						i--;
						if(i<=0){
							clearInterval(reSend);
							$("#getCode").removeClass("canot").val("获取验证码");
						}else{
							$("#getCode").addClass("canot").val(i+"秒后获取");	
						}
					},1000);
				}else{
					popBox("提示",data.errmsg);
				}
			}
		});	
	});
	
	$("#forget").submit(function(){
		if(!checkPhone($("#cellphone").val())){
			$("#cellphone").parent().next("td").find("span").html("<span class=red>请输入正确手机号</span>");
			$("#cellphone").focus();
			return false;	
		}else{
			$("#cellphone").parent().next("td").find("span").html("√");	
		}
		if($("#randomCode").val().length != 6){
			$("#randomCode").parent().next("td").find("span").html("<span class=red>请输入6位数字验证码</span>");
			$("#randomCode").focus();
			return false;	
		}else{
			$("#randomCode").parent().next("td").find("span").html("");	
		}	
		var options = {
			url: contextPath+"/media/user/open/resetPassword.do",
			success: function(data) {
				if(data.status == 0){
					location.href=contextPath+"/media/user/open/resetOk.do";
				}else{
					popBox("验证失败",data.errmsg);
				}
			}
		};		 
		$("#forget").ajaxSubmit(options);
		return false;
		
	});	
	
	
}); 

